package model

import (
	"gitee.com/sdumeeting/sfu-server/pkg/util"
)

type User struct {

	// 用户 id
	id int

	// 用户昵称
	name string

	Conn *Connection
}

type UserInfo struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
}

func NewUser(id int, name string, conn *Connection) *User {
	var user User
	user.id = id
	user.name = name
	user.Conn = conn
	return &user
}

func (u *User) Close() {
	u.Conn.Close()
}

func (u *User) GetId() int {
	return u.id
}

func (u *User) GetName() string {
	return u.name
}

// GetUserInfo 获取用户信息
func (u *User) GetUserInfo() *UserInfo {
	return &UserInfo{Id: u.id, Name: u.name}
}

func (u *User) SendMessage(messageType string, data map[string]interface{}) {
	_ = u.Conn.Send(util.Marshal(map[string]interface{}{
		"type": messageType,
		"data": data,
	}))
}
